package com.atguigu.tingshu.order.config;

import com.atguigu.tingshu.common.constant.TingShuMqConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OrderMqConfig {
    @Bean
    public Queue ttlQueue(){
        return QueueBuilder.durable(TingShuMqConstants.ORDER_TTL_QUEUE)
                .ttl(TingShuMqConstants.ORDER_TTL_TIME)
                .deadLetterExchange(TingShuMqConstants.ORDER_EXCHANGE)
                .deadLetterRoutingKey(TingShuMqConstants.ORDER_DEAD_RK).build();
    }

    @Bean
    public Binding ttlBinding(){
        return new Binding(TingShuMqConstants.ORDER_TTL_QUEUE,Binding.DestinationType.QUEUE,
                TingShuMqConstants.ORDER_EXCHANGE,TingShuMqConstants.ORDER_TTL_RK,null);
    }

    @Bean
    public Queue deadQueue(){
        return QueueBuilder.durable(TingShuMqConstants.ORDER_DEAD_QUEUE).build();
    }

    @Bean
    public Binding deadBinding(){
        return new Binding(TingShuMqConstants.ORDER_DEAD_QUEUE,Binding.DestinationType.QUEUE,
                TingShuMqConstants.ORDER_EXCHANGE,TingShuMqConstants.ORDER_DEAD_RK,null);
    }
}
